package com.nbsaas.boot.example.rest.convert;

import com.nbsaas.boot.example.data.entity.ExampleCatalog;
import com.nbsaas.boot.example.api.domain.request.ExampleCatalogRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.example.data.entity.ExampleCatalog;
            import com.nbsaas.boot.jpa.data.entity.User;

/**
* 案例分类请求对象转换成实体对象
*/

public class ExampleCatalogEntityConvert  implements Converter<ExampleCatalog, ExampleCatalogRequest> {

    @Override
    public ExampleCatalog convert(ExampleCatalogRequest source) {
        ExampleCatalog result = new ExampleCatalog();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getParent()!=null){
                    ExampleCatalog parent =new ExampleCatalog();
                    parent.setId(source.getParent());
                    result.setParent(parent);
                    }
                    if(source.getCreator()!=null){
                    User creator =new User();
                    creator.setId(source.getCreator());
                    result.setCreator(creator);
                    }
        return result;
    }
}

